package leetcode.code1433;

import java.util.Arrays;

public class Solution {
	public boolean checkIfCanBreak(String s1, String s2) {
		char[] cs1 = s1.toCharArray();
		char[] cs2 = s2.toCharArray();
		Arrays.sort(cs1);
		Arrays.sort(cs2);
		int p = 0;
		while (p < cs1.length && cs1[p] == cs2[p]) {
			p++;
		}
		if (p == cs1.length) {
			return true;
		}
		if (cs1[p] > cs2[p]) {
			return this.f(cs1, cs2, p);
		} else {
			return this.f(cs2, cs1, p);
		}
	}

	private boolean f(char[] cs1, char[] cs2, int p) {
		while (p < cs1.length) {
			if (cs1[p] < cs2[p]) {
				return false;
			}
			p++;
		}
		return true;
	}
}
